//
//  Radio_Ting_TableViewCell.m
//  Time
//
//  Created by dllo on 16/7/23.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Radio_Ting_TableViewCell.h"
#import "Radio_Ting_CollectionViewCell.h"

@interface Radio_Ting_TableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,retain) UICollectionView *TingCollectionView;

@end

@implementation Radio_Ting_TableViewCell


-(void)dealloc{
    [_tingArray release];
    [_TingCollectionView release];
    self.TingCollectionView.dataSource = nil;
    self.TingCollectionView.delegate = nil;
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake((SWIDTH - 10) / 3.0, SWIDTH / 3 + 50);
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0;
        self.TingCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SWIDTH, (SWIDTH / 3 + 50) * 2) collectionViewLayout:flowLayout];
        [self.contentView addSubview:self.TingCollectionView];
        self.TingCollectionView.backgroundColor = [UIColor whiteColor];
        self.TingCollectionView.delegate = self;
        self.TingCollectionView.dataSource = self;
        [self.TingCollectionView registerClass:[Radio_Ting_CollectionViewCell class] forCellWithReuseIdentifier:@"Radio_Ting_CollectionView_Cell"];
        [_TingCollectionView release];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
//    [self.TingCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.contentView.mas_left).offset(0);
//        make.right.equalTo(self.contentView.mas_right).offset(0);
//        make.top.equalTo(self.contentView.mas_top).offset(0);
//        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
//    }];
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.tingArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    Radio_Ting_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Radio_Ting_CollectionView_Cell" forIndexPath:indexPath];
//    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 255 / 255.0 green:arc4random() % 255 / 255.0 blue:arc4random() % 255 / 255.0 alpha:1.0];
    cell.model = [self.tingArray objectAtIndex:indexPath.item];
    return cell;
}


-(void)setTingArray:(NSMutableArray *)tingArray{
    if (_tingArray != tingArray) {
        [_tingArray release];
        _tingArray = [tingArray retain];
    }
    /**
     *  刷新数据!!!!!
     */
    if (tingArray.count < 6){
        self.TingCollectionView.frame = CGRectMake(0, 0, SWIDTH, SWIDTH / 3 + 50);
    } else {
        self.TingCollectionView.frame = CGRectMake(0, 0, SWIDTH, (SWIDTH / 3 + 50) * 2);
    }
    [self.TingCollectionView reloadData];
}


@end
